package it.irondev.appturismo.dao;

import it.irondev.appturismo.dao.example.AccomodationsExample;
import it.irondev.appturismo.dao.provider.AccomodationsSqlProvider;
import it.irondev.appturismo.entity.Accomodation;
import it.irondev.appturismo.entity.Accomodationtype;
import it.irondev.appturismo.entity.City;
import it.irondev.appturismo.entity.Gallery;
import it.irondev.appturismo.entity.Language;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface AccomodationsMapper {
	@SelectProvider(type=AccomodationsSqlProvider.class, method="countByExample")
	int countByExample(AccomodationsExample example);

	@DeleteProvider(type=AccomodationsSqlProvider.class, method="deleteByExample")
	int deleteByExample(AccomodationsExample example);

	@Delete({
		"delete from Accomodations",
		"where idAccomodation = #{idaccomodation,jdbcType=INTEGER}"
	})
	int deleteByPrimaryKey(Integer idaccomodation);

	@Insert({
		"insert into Accomodations ( name, ",
		"address, phone, ",
		"email, web, description, ",
		"city, position, gallery, ",
		"type, language)",
		"values ( #{name,jdbcType=VARCHAR}, ",
		"#{address,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, ",
		"#{email,jdbcType=VARCHAR}, #{web,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, ",
		"#{city.idcity,jdbcType=INTEGER}, #{position,jdbcType=VARCHAR}, #{gallery.idgallery,jdbcType=INTEGER}, ",
		"#{type.idaccomodationtype,jdbcType=INTEGER}, #{language.idlanguage,jdbcType=INTEGER})"
	})
	@Options(useGeneratedKeys = true, keyProperty="idAccomodation")
	int insert(Accomodation record);

	@InsertProvider(type=AccomodationsSqlProvider.class, method="insertSelective")
	int insertSelective(Accomodation record);

	@SelectProvider(type=AccomodationsSqlProvider.class, method="selectByExample")
	@Results({
		@Result(column="idAccomodation", property="idaccomodation", jdbcType=JdbcType.INTEGER, id=true),
		@Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
		@Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
		@Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
		@Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
		@Result(column="web", property="web", jdbcType=JdbcType.VARCHAR),
		@Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
		@Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="type", property="type", javaType=Accomodationtype.class, one=@One(select="it.irondev.appturismo.dao.AccomodationtypeMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey"))
	})
	List<Accomodation> selectByExample(AccomodationsExample example);

	@Select({
		"select",
		"idAccomodation, name, address, phone, email, web, description, city, position, ",
		"type, language",
		"from Accomodations",
		"where idAccomodation = #{idaccomodation,jdbcType=INTEGER}"
	})
	@Results({
		@Result(column="idAccomodation", property="idaccomodation", jdbcType=JdbcType.INTEGER, id=true),
		@Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
		@Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
		@Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
		@Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
		@Result(column="web", property="web", jdbcType=JdbcType.VARCHAR),
		@Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
		@Result(column="city", property="city", javaType=City.class, one=@One(select="it.irondev.appturismo.dao.CityMapper.selectByPrimaryKey")),
		@Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
		@Result(column="gallery", property="gallery", javaType=Gallery.class, one=@One(select="it.irondev.appturismo.dao.GalleryMapper.selectByPrimaryKey")),
		@Result(column="type", property="type", javaType=Accomodationtype.class, one=@One(select="it.irondev.appturismo.dao.AccomodationtypeMapper.selectByPrimaryKey")),
		@Result(column="language", property="language", javaType=Language.class, one=@One(select="it.irondev.appturismo.dao.LanguageMapper.selectByPrimaryKey"))
	})
	Accomodation selectByPrimaryKey(Integer idaccomodation);

	@UpdateProvider(type=AccomodationsSqlProvider.class, method="updateByExampleSelective")
	int updateByExampleSelective(@Param("record") Accomodation record, @Param("example") AccomodationsExample example);

	@UpdateProvider(type=AccomodationsSqlProvider.class, method="updateByExample")
	int updateByExample(@Param("record") Accomodation record, @Param("example") AccomodationsExample example);

	@UpdateProvider(type=AccomodationsSqlProvider.class, method="updateByPrimaryKeySelective")
	int updateByPrimaryKeySelective(Accomodation record);

	@Update({
		"update Accomodations",
		"set name = #{name,jdbcType=VARCHAR},",
		"address = #{address,jdbcType=VARCHAR},",
		"phone = #{phone,jdbcType=VARCHAR},",
		"email = #{email,jdbcType=VARCHAR},",
		"web = #{web,jdbcType=VARCHAR},",
		"description = #{description,jdbcType=VARCHAR},",
		"city = #{city.idcity,jdbcType=INTEGER},",
//		"gallery = #{gallery.idgallery,jdbcType=INTEGER},",
		"position = #{position,jdbcType=VARCHAR},",
		"type = #{type.idaccomodationtype,jdbcType=INTEGER},",
		"language = #{language.idlanguage,jdbcType=INTEGER}",
		"where idAccomodation = #{idaccomodation,jdbcType=INTEGER}"
	})
	int updateByPrimaryKey(Accomodation record);
}